﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Huirui.Cavan.Core.MyLinq;
using Huirui.Cavan.Core.Persistent;
using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
using Huirui.Cavan.Core.Extension;

namespace Huirui.Cavan.Domain.MainBoundedContext.StockModule
{
    public class UnitTransferSpecification : ISpecification<UnitTransfer, UnitTransferSearch>
    {
        #region ISpecification<UnitTransfer,UnitTransferSearch> 成员

        public UnitTransferSearch SearchParams
        {
            get;
            set;
        }

        #endregion

        #region ISpecification<UnitTransfer> 成员

        public System.Linq.Expressions.Expression<Func<UnitTransfer, bool>> Expression
        {
            get
            {
                IQueryBuilder<UnitTransfer> queryBuilder = QueryBuilder.Create<UnitTransfer>();

                if (SearchParams.IsNotNull())
                {
                    if (SearchParams.ID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(ut => ut.Id, SearchParams.ID);
                    }
                    if (SearchParams.FromStockUnitID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(ut => ut.FromUnit.Id, SearchParams.FromStockUnitID);
                    }
                    if (SearchParams.ToStockUnitID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(ut => ut.ToUnit.Id, SearchParams.ToStockUnitID);
                    }
                    if (SearchParams.FromNumber > 0)
                    {
                        queryBuilder = queryBuilder.Equals(ut => ut.FromNumber, SearchParams.FromNumber);
                    }
                    if (SearchParams.FromStockUnitID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(ut => ut.ToNumber, SearchParams.ToNumber);
                    }
                }

                return queryBuilder.Expression.Expand();
            }
        }

        #endregion
    }
}
